package btp.Calendars;

public class HinduMeanSolarCalendar {

	
	public static final long EPOCH = -1132959;//GregorianCalendar.getRDFromGregorian(-3101, GregorianCalendar.JANUARY, 23);
	
	public static final double SIDEREAL_YEAR = 1577917828.0/4320000.0;//1577917828.0/4320000.0;
	public static final double JOVIAN_YEAR = SIDEREAL_YEAR/364220.0;
	public static final double SIDEREAL_MONTH = SIDEREAL_YEAR/12;
	public static final double LUNAR_MONTH = 1577917828.0/53433336.0;
	public static final double LUNAR_DAY = LUNAR_MONTH/30;
	
	int year;
	int month;
	int day;
	
	public HinduMeanSolarCalendar(int year, int month, int day){
		this.year = year;
		this.month = month;
		this.day = day;
	}
	
	public final int getYear() {
		return year;
	}


	public final void setYear(int year) {
		this.year = year;
	}


	public final int getMonth() {
		return month;
	}


	public final void setMonth(int month) {
		this.month = month;
	}


	public final int getDay() {
		return day;
	}


	public final void setDay(int day) {
		this.day = day;
	}

	public long getRDFromSolarCalendar(){
		return getRDFromSolarCalendar(year, month, day);
	}
	
	public long getDayCountFromCalendar(){
		return getDayCountFromCalendar()-EPOCH;
	}
	
	public static long getDayCountFromRD(long rd){
		return rd-EPOCH;
	}
	
	public static int getJovianYearFromDayCount(long hinduDayCount){
		return (int) (27 + Math.floor(hinduDayCount*12/JOVIAN_YEAR)%60);
	}
	
	
	public static long getRDFromSolarCalendar(int year, int month, int day){
		return (long) Math.ceil(EPOCH+year*SIDEREAL_YEAR+(month-1)*SIDEREAL_MONTH+day-1.25);
	}
	
	public static HinduMeanSolarCalendar getCalendarFromRD(int rd){
		double sun = getDayCountFromRD(rd) + 0.25;
		int year = (int) Math.floor(sun/SIDEREAL_YEAR);
		int month = (int) ((Math.floor(sun/SIDEREAL_MONTH)%12 + 12)%12 + 1);
		int day = (int) (sun%SIDEREAL_MONTH + 1);
		
		return new HinduMeanSolarCalendar(year, month, day);
	}
	
	 
}
